﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace lso_2u_Web应用开发.Models.Database
{
    public partial class DressWorkSystemContext : DbContext
    {
        public DressWorkSystemContext()
        {
        }

        public DressWorkSystemContext(DbContextOptions<DressWorkSystemContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Chat> Chats { get; set; }
        public virtual DbSet<Factory> Factories { get; set; }
        public virtual DbSet<Order> Orders { get; set; }
        public virtual DbSet<Supplier> Suppliers { get; set; }
        public virtual DbSet<Task> Tasks { get; set; }
        public virtual DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=DressWorkSystem;Integrated Security=SSPI");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Chat>(entity =>
            {
                entity.Property(e => e.MessageData).IsUnicode(false);

                entity.Property(e => e.MessageType)
                    .IsUnicode(false)
                    .HasDefaultValueSql("('text')")
                    .HasComment("类型为text以及order");

                entity.Property(e => e.SendTime).HasDefaultValueSql("(getdate())");
            });

            modelBuilder.Entity<Factory>(entity =>
            {
                entity.Property(e => e.Address).HasComment("工厂地址");

                entity.Property(e => e.BindCode)
                    .IsUnicode(false)
                    .HasComment("邀请码");

                entity.Property(e => e.ChargeName).HasComment("负责人姓名");

                entity.Property(e => e.ChargePhoneNumber)
                    .IsUnicode(false)
                    .HasComment("负责人手机号");

                entity.Property(e => e.FkBindUser).HasComment("绑定到的用户");

                entity.Property(e => e.WorkType).HasComment("加工业务类型");
            });

            modelBuilder.Entity<Order>(entity =>
            {
                entity.Property(e => e.CreateTime)
                    .HasDefaultValueSql("(getdate())")
                    .HasComment("创建时间");

                entity.Property(e => e.FkCreateUserId).HasComment("创建人id");

                entity.Property(e => e.FkSupplierId).HasComment("货源id");

                entity.Property(e => e.Notes)
                    .HasDefaultValueSql("('')")
                    .HasComment("备注");

                entity.Property(e => e.PaymentTime).HasComment("支付时间, 订单完结");

                entity.Property(e => e.StartTime).HasComment("接受时间");

                entity.Property(e => e.StyleNumber)
                    .IsUnicode(false)
                    .HasComment("款号");
            });

            modelBuilder.Entity<Supplier>(entity =>
            {
                entity.Property(e => e.Address).HasComment("货源地址");

                entity.Property(e => e.BindCode)
                    .IsUnicode(false)
                    .HasComment("邀请码");

                entity.Property(e => e.ChargeName).HasComment("负责人姓名");

                entity.Property(e => e.ChargePhoneNumber)
                    .IsUnicode(false)
                    .HasComment("负责人手机号");

                entity.Property(e => e.FkBindUser).HasComment("绑定到的用户, 非强制要求绑定到用户");
            });

            modelBuilder.Entity<Task>(entity =>
            {
                entity.Property(e => e.CompleteTime).HasComment("完成时间");

                entity.Property(e => e.CreateTime)
                    .HasDefaultValueSql("(getdate())")
                    .HasComment("创建时间, 默认为当前时间");

                entity.Property(e => e.FkFactoryId).HasComment("关联的加工厂");

                entity.Property(e => e.FkOrderId).HasComment("关联的订单");

                entity.Property(e => e.Notes)
                    .HasDefaultValueSql("('')")
                    .HasComment("备注");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.Property(e => e.Actor)
                    .IsUnicode(false)
                    .HasDefaultValueSql("('user')")
                    .HasComment("角色名称, 权限");

                entity.Property(e => e.Name).HasComment("用户名");

                entity.Property(e => e.Password).HasComment("密码");

                entity.Property(e => e.PhoneNumber)
                    .IsUnicode(false)
                    .HasComment("手机号, 也用作登录");

                entity.Property(e => e.SecretKey)
                    .IsUnicode(false)
                    .HasComment("2FA密钥");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
